package com.java.agent;

import java.lang.instrument.Instrumentation;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * vm option
 * -javaagent:E:\java-enhance\java-agent\target\java-agent.jar=thisIsAgentArgs
 */
public class JavaAgent {

    public static void premain(String agentArgs, Instrumentation inst) {
        System.out.println("Java Agent args :"+agentArgs);

        Executors.newScheduledThreadPool(1).scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                JvmStack.printMemoryInfo();
                JvmStack.printGCInfo();
                System.out.println("===================================================================================================");
            }
        }, 0, 5000, TimeUnit.MILLISECONDS);

        inst.addTransformer(new SimClassFileTransformer());
    }

    public static void premain(String agentArgs) {
    }
}
